package Tests;

import junit.framework.Assert;

import org.jmock.Expectations;
import org.jmock.Mockery;
import org.junit.Test;

import Core.Character;
import Core.Map.CharacterMoverImpl;
import Core.Map.CombatGrid;
import Core.Map.Tile;

public class CharacterMoverImplTests
{
	@Test
	public void gridCanMoveCharacter()
	{
		Mockery context = new Mockery();
		
		final Tile destinationTile = new Tile(2, 3);
		final Character character = context.mock(Character.class);
		final CombatGrid grid = context.mock(CombatGrid.class);
		
		context.checking(new Expectations()
		{{
			one(grid).getTileWithCharacter(character); will(returnValue(null));
			one(grid).getTile(2, 3); will(returnValue(destinationTile));
		}});
		
		CharacterMoverImpl mover = new CharacterMoverImpl();
	
		mover.moveCharacter(grid, character, 2, 3);
		
		Assert.assertTrue(destinationTile.containsCharacter(character));
	}
	

	@Test
	public void movingCharacterRemovesCharacterFromOriginalTile()
	{
		Mockery context = new Mockery();
		
		final Character character = context.mock(Character.class);
		final CombatGrid grid = context.mock(CombatGrid.class);
		final Tile originalTile = new Tile(2, 2);
		final Tile destinationTile = new Tile(1, 1);

		context.checking(new Expectations()
		{{
			one(grid).getTileWithCharacter(character); will(returnValue(originalTile));
			one(grid).getTile(1, 1); will(returnValue(destinationTile));
		}});
		
		originalTile.addCharacter(character);
		
		CharacterMoverImpl mover = new CharacterMoverImpl();
		
		mover.moveCharacter(grid, character, 1, 1);
		
		Assert.assertFalse(originalTile.containsCharacter(character));
	}
}
